#include common_scripts\utility;
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include z_mod\_utility;


init()
{
    level thread onPlayerConnected();
    
    precacheShader("cardtitle_locked");
}

onPlayerConnected()
{
    for(;;) {
        level waittill("connected", player);
        
        player thread onPlayerDied();
        player thread onPlayerSpawned();
        
        player createHUD_Energy();
        player createHUD_Health();
        player createHUD_Skills();
        player createHUD_SoulSelect();
    }
}

onPlayerDied()
{
    self endon("disconnect");
    
    for(;;) {
        self waittill("death");
        
        self thread hideHUD_Energy();
        self thread hideHUD_Health();
    }
}

onPlayerSpawned()
{
    self endon("disconnect");
    
    for(;;) {
        self waittill("spawned_player");
        
        self thread showHUD_Energy();
        self thread showHUD_Health();
    }
}

createHUD_Energy()
{
    self.z_HUDEnergy = self createFontString("hudbig", 0.7);
    self.z_HUDEnergy setPoint("CENTER", "BOTTOM RIGHT", -65, -15, 0);
    self.z_HUDEnergy setText("/");
    
    self.z_HUDEnergyBar = self createBar((0, 0, 0.65), 100, 15);
    self.z_HUDEnergyBar setPoint("CENTER", "CENTER", 0, 0, 0);
    self.z_HUDEnergyBar updateBar(1.0);
    self.z_HUDEnergyBar setParent(self.z_HUDEnergy);
    
    self.z_HUDEnergyCurrent = self createFontString("hudbig", 0.7);
    self.z_HUDEnergyCurrent setPoint("RIGHT", "RIGHT", -5, 0, 0);
    self.z_HUDEnergyCurrent setParent(self.z_HUDEnergy);
    
    self.z_HUDEnergyMax = self createFontString("hudbig", 0.7);
    self.z_HUDEnergyMax setPoint("LEFT", "LEFT", 5, 0, 0);
    self.z_HUDEnergyMax setParent(self.z_HUDEnergy);
    
    self.z_HUDEnergy thread z_DestroyAfterDisconnect(self);
    self.z_HUDEnergyBar thread z_DestroyAfterDisconnect(self);
    self.z_HUDEnergyCurrent thread z_DestroyAfterDisconnect(self);
    self.z_HUDEnergyMax thread z_DestroyAfterDisconnect(self);
    
    self hideHUD_Energy();
}

createHUD_Health()
{
    self.z_HUDHealth = self createFontString("hudbig", 0.7);
    self.z_HUDHealth setPoint("CENTER", "BOTTOM LEFT", 65, -15, 0);
    self.z_HUDHealth setText("/");
    
    self.z_HUDHealthBar = self createBar((0.65, 0, 0), 100, 15);
    self.z_HUDHealthBar setPoint("CENTER", "CENTER", 0, 0, 0);
    self.z_HUDHealthBar updateBar(1.0);
    self.z_HUDHealthBar setParent(self.z_HUDHealth);
    
    self.z_HUDHealthCurrent = self createFontString("hudbig", 0.7);
    self.z_HUDHealthCurrent setPoint("RIGHT", "RIGHT", -5, 0, 0);
    self.z_HUDHealthCurrent setParent(self.z_HUDHealth);
    
    self.z_HUDHealthMax = self createFontString("hudbig", 0.7);
    self.z_HUDHealthMax setPoint("LEFT", "LEFT", 5, 0, 0);
    self.z_HUDHealthMax setParent(self.z_HUDHealth);
    
    self.z_HUDHealth thread z_DestroyAfterDisconnect(self);
    self.z_HUDHealthBar thread z_DestroyAfterDisconnect(self);
    self.z_HUDHealthCurrent thread z_DestroyAfterDisconnect(self);
    self.z_HUDHealthMax thread z_DestroyAfterDisconnect(self);
    
    self hideHUD_Health();
}

createHUD_Skills()
{
    self.z_HUDSkills = [];
    self.z_HUDSkillsText = [];
    
    self.z_HUDSkills[0] = self createIcon("cardicon_locked", 24, 24);
    self.z_HUDSkills[0] setPoint("BOTTOM", "BOTTOM", -45, -1, 0);
    
    self.z_HUDSkillsText[0] = self createFontString("hudbig", 0.5);
    self.z_HUDSkillsText[0].color = (1, 1, 0);
    self.z_HUDSkillsText[0] setPoint("CENTER", "BOTTOM RIGHT", -5, -5, 0);
    self.z_HUDSkillsText[0] setParent(self.z_HUDSkills[0]);
    self.z_HUDSkillsText[0] setText("[{+actionslot 1}]");
    
    self.z_HUDSkills[1] = self createIcon("cardicon_locked", 24, 24);
    self.z_HUDSkills[1] setPoint("BOTTOM", "BOTTOM", -15, -1, 0);
    
    self.z_HUDSkillsText[1] = self createFontString("hudbig", 0.5);
    self.z_HUDSkillsText[1].color = (1, 1, 0);
    self.z_HUDSkillsText[1] setPoint("CENTER", "BOTTOM RIGHT", -5, -5, 0);
    self.z_HUDSkillsText[1] setParent(self.z_HUDSkills[1]);
    self.z_HUDSkillsText[1] setText("[{+actionslot 2}]");
    
    self.z_HUDSkills[2] = self createIcon("cardicon_locked", 24, 24);
    self.z_HUDSkills[2] setPoint("BOTTOM", "BOTTOM", 15, -1, 0);
    
    self.z_HUDSkillsText[2] = self createFontString("hudbig", 0.5);
    self.z_HUDSkillsText[2].color = (1, 1, 0);
    self.z_HUDSkillsText[2] setPoint("CENTER", "BOTTOM RIGHT", -5, -5, 0);
    self.z_HUDSkillsText[2] setParent(self.z_HUDSkills[2]);
    self.z_HUDSkillsText[2] setText("[{+actionslot 3}]");
    
    self.z_HUDSkills[3] = self createIcon("cardicon_locked", 24, 24);
    self.z_HUDSkills[3] setPoint("BOTTOM", "BOTTOM", 45, -1, 0);
    
    self.z_HUDSkillsText[3] = self createFontString("hudbig", 0.5);
    self.z_HUDSkillsText[3].color = (1, 1, 0);
    self.z_HUDSkillsText[3] setPoint("CENTER", "BOTTOM RIGHT", -5, -5, 0);
    self.z_HUDSkillsText[3] setParent(self.z_HUDSkills[3]);
    self.z_HUDSkillsText[3] setText("[{+actionslot 4}]");
    
    self.z_HUDSkills[0] thread z_DestroyAfterDisconnect(self);
    self.z_HUDSkillsText[0] thread z_DestroyAfterDisconnect(self);
    self.z_HUDSkills[1] thread z_DestroyAfterDisconnect(self);
    self.z_HUDSkillsText[1] thread z_DestroyAfterDisconnect(self);
    self.z_HUDSkills[2] thread z_DestroyAfterDisconnect(self);
    self.z_HUDSkillsText[2] thread z_DestroyAfterDisconnect(self);
    self.z_HUDSkills[3] thread z_DestroyAfterDisconnect(self);
    self.z_HUDSkillsText[3] thread z_DestroyAfterDisconnect(self);
    
    self hideHUD_Skills();
}

createHUD_SoulSelect()
{
    self.z_HUDSoulSelect = self createIcon("cardtitle_locked", 120, 24);
    self.z_HUDSoulSelect setPoint("CENTER", "CENTER", 0, -50, 0);
    
    self.z_HUDSoulSelectText = self createFontString("hudbig", 0.7);
    self.z_HUDSoulSelectText setPoint("CENTER", "CENTER", 0, 0, 0);
    self.z_HUDSoulSelectText setParent(self.z_HUDSoulSelect);
    
    self.z_HUDSoulSelect thread z_DestroyAfterDisconnect(self);
    self.z_HUDSoulSelectText thread z_DestroyAfterDisconnect(self);
    
    self hideHUD_SoulSelect();
}

hideHUD_Energy()
{
    self.z_HUDEnergy hideElem();
    self.z_HUDEnergyBar hideElem();
    self.z_HUDEnergyCurrent hideElem();
    self.z_HUDEnergyMax hideElem();
}

hideHUD_Health()
{
    self.z_HUDHealth hideElem();
    self.z_HUDHealthBar hideElem();
    self.z_HUDHealthCurrent hideElem();
    self.z_HUDHealthMax hideElem();
}

hideHUD_Skills()
{
    self.z_HUDSkills[0] hideElem();
    self.z_HUDSkillsText[0] hideElem();
    self.z_HUDSkills[1] hideElem();
    self.z_HUDSkillsText[1] hideElem();
    self.z_HUDSkills[2] hideElem();
    self.z_HUDSkillsText[2] hideElem();
    self.z_HUDSkills[3] hideElem();
    self.z_HUDSkillsText[3] hideElem();
}

hideHUD_SoulSelect()
{
    self.z_HUDSoulSelect hideElem();
    self.z_HUDSoulSelectText hideElem();
}

showHUD_Energy()
{
    self endon("death");
    self endon("disconnect");
    
    if(self.z_SoulCurrent == -1)
        self waittill("changed_kit");
    
    self.z_HUDEnergy showElem();
    self.z_HUDEnergyBar showElem();
    self.z_HUDEnergyCurrent showElem();
    self.z_HUDEnergyMax showElem();
    
    self.z_HUDEnergyMax setValue(self.z_EnergyMax);
    
    while(true) {
        self.z_HUDEnergyBar updateBar(self.z_Energy / self.z_EnergyMax);
        self.z_HUDEnergyCurrent setValue(self.z_Energy);
        
        wait(0.25);
    }
}

showHUD_Health()
{
    self endon("death");
    self endon("disconnect");
    
    if(self.z_SoulCurrent == -1)
        self waittill("changed_kit");
    
    self.z_HUDHealth showElem();
    self.z_HUDHealthBar showElem();
    self.z_HUDHealthCurrent showElem();
    self.z_HUDHealthMax showElem();
    
    self.z_HUDHealthMax setValue(self.maxhealth);
    
    while(true) {
        self.z_HUDHealthBar updateBar(self.health / self.maxhealth);
        self.z_HUDHealthCurrent setValue(self.health);
        
        wait(0.25);
    }
}

showHUD_Skills()
{
    self.z_HUDSkills[0] showElem();
    self.z_HUDSkillsText[0] showElem();
    self.z_HUDSkills[1] showElem();
    self.z_HUDSkillsText[1] showElem();
    self.z_HUDSkills[2] showElem();
    self.z_HUDSkillsText[2] showElem();
    self.z_HUDSkills[3] showElem();
    self.z_HUDSkillsText[3] showElem();
}

showHUD_SoulSelect()
{
    self.z_HUDSoulSelect showElem();
    self.z_HUDSoulSelectText showElem();
}

